/*
*************************************************************************
*西瑞克斯研发管理系统
*版 本: 1.0   
*日 期：02/20/2012    
*作 者： 王浩 QQ：873987060   
*************************************************************************   
*/ 
package com.manager.word;

import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import org.apache.log4j.Logger;

import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;

/**
 * @author 王浩 QQ：873987060   
 *
 */
public class FreeMarkerFactory {
	private static Logger log = Logger.getLogger(FreeMarkerFactory.class);
	private static FreeMarkerFactory instance = new FreeMarkerFactory();
	
	private static Configuration cfg;
	
	private FreeMarkerFactory(){}
	
	public static FreeMarkerFactory getInstance(String templetePath){
		cfg = new Configuration();
		File file = new File(templetePath);
		try {
			cfg.setDirectoryForTemplateLoading(file);
			cfg.setObjectWrapper(new DefaultObjectWrapper());
			cfg.setDefaultEncoding("UTF-8");
			cfg.setOutputEncoding("UTF-8");
		} catch (IOException e) {
			log.error("模板文件不存在" + e);
		}
		return instance;
	}
	
	public void processTemplete(Map mapValue,String ftl,Writer out){
		try {
			Template t = cfg.getTemplate(ftl,"UTF-8");
			t.process(mapValue, out);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	 
	}
}
